﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TaiLieu;
using System.IO;
public partial class TracNghiem_1L : System.Web.UI.UserControl
{
    public string _Url = "";
    int parent = 0;
    public string _link = "";
    DataTable tb = null;
    string fileName = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        LoadData();
        grid.RowCancelingEdit += delegate { Response.Redirect(Request.Url.ToString()); };
       
    }
    protected void LoadData()
    {

        DataBind(TracNghiem_MembersDB.GetObjectBy_Id_Level_Mem(Sessions.members.Id));
    }
    void DataBind(object al)
    {
        if (al != null)
        {
            grid.DataKeyNames = new string[] { Colum_TracNghiem_Members.Id };
            grid.DataSource = al;
            grid.DataBind();
        }
    }
    protected void btnSetupAnswer_Click(object sender, EventArgs e)
    {
        foreach (string key in Request.Form.AllKeys)
        {
            if (key.Contains("check") == true)
            {

                TracNghiem tn = TracNghiemDB.GetObjectByid(Get_ID(key), true, QueryHelper.Get_Domain_1_maHoa(Request));
                tn.answer = Get_value(key, 1);
                TracNghiemDB.Save(tn);
            }
        }
    }

    //
    public static string Get_ID(string str)
    {
        return Get_value(str, str.Split('_').Length);
    }
    public static string Get_value(string str, int possition)
    {
        return str.Split('_')[possition - 1];
    }
   
    protected void grid_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grid.PageIndex = e.NewPageIndex;
    }

}
